package org.example.footshoppingmaster.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.footshoppingmaster.pojo.DO.User;
@Mapper
public interface UserMapper {
    /*
    * 用户登录
    * */
    @Select("select * from t_user where email=#{email} and password=#{password};")
     User getByEmailAndPassword(String email,String password);
    /*
    * 根据email查询用户是否存在
    * */
    @Select("select * from t_user where email=#{email}")
    User getByEmail(String email);
    /*
    * 添加用户
    * */
    @Insert("INSERT INTO t_user(name,phon,password,sex,email,age,sign) " +
            "values (#{name},#{phon},#{password},#{sex},#{email},#{age},#{sign})")
    int insert(User user);
    /*
    * 更新用户信息
    * */
    int updateUser(User user);
    /*
    * 根据id查询用户信息
    * */
    @Select("select * from t_user where id=#{id}")
    User getById(Integer id);
    /*
    * 用户密码修改
    * */
    @Update("UPDATE t_user SET password=#{newPwd} WHERE id =#{id} AND password = #{ oldPwd};")
    void setPassword(Integer id,String oldPwd, String newPwd);
     /*
     * 获取用户信息
     * */
    @Select("select * from t_user where name=#{userName}  ")
    User getUserByUsername(String userName);
    /*
    *
    * */
    @Update("update t_user set avatar=#{avatar} where id=#{id} ")
    boolean updateAvatar(Integer id, String avatar);
}
